package com.wujunshen.algorithm.leetcode.basic;

import java.util.HashMap;
import java.util.Map;

/**
 * @author frank woo(吴峻申) <br>
 *     email:<a href="mailto:frank_wjs@hotmail.com">frank_wjs@hotmail.com</a> <br>
 * @date 2022/7/24 00:13<br>
 */
public class 单词规律 {
  public static boolean wordPattern(String pattern, String str) {
    String[] words = str.split(" ");
    if (words.length != pattern.length()) {
      return false;
    }
    Map index = new HashMap();
    for (Integer i = 0; i < words.length; i++) {
      if (index.put(pattern.charAt(i), i) != index.put(words[i], i)) {
        return false;
      }
    }
    return true;
  }
}
